package cn.ichar.provide.mq;


import org.apache.dubbo.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author imaye
 * @date 2021/8/19
 */
@RestController
public class MsgController {
    @Value("${rocketmq.producer.topic}")
    private String topic;

    @Resource
    private SpringProducer mqSender;

    //发送消息
    @GetMapping("/sendMsg")
    public String sendMsg(String msg) {
        if (!StringUtils.isEmpty(msg)) {
            mqSender.sendMessage(msg, topic);
            return "ok";
        }
        return "请输入要发送的消息";
    }

    //发送事务消息
    @GetMapping("/sendTransactionMsg")
    public String sendTransactionMsg(String msg) {
        if (!StringUtils.isEmpty(msg)) {
            mqSender.sendMessageIntransaction(msg, topic);
            return "ok";
        }
        return "请输入要发送的消息";
    }
}
